layui.define(["element", "jquery", 'form'], function (exports) {
	var element = layui.element,
		$ = layui.jquery,
		device = layui.device(),
		commonLayer = function () { };

	commonLayer.prototype.set = function (option) {
		var _this = this;
		$.extend(true, _this.config, option);
		return _this;
	};

	/*
	 * 错误提示消息
	 * _msg: 提示消息
	 */
	commonLayer.prototype.errorMsg = function (_msg) {
		layer.msg(_msg, {
			// icon: 5,
			shift: 6 //抖动
		});
	};

	/*
	 * 成功提示消息
	 * _msg: 提示消息
	 */
	commonLayer.prototype.successMsg = function (_msg) {
		layer.msg(_msg === null ? "操作成功" : _msg, {
			// icon: 1
		});
	};

	/*
	 * 警告提示消息
	 * _msg: 提示消息
	 */
	commonLayer.prototype.warnMsg = function (_msg) {
		layer.msg(_msg, {
			// icon: 2
		});
	};

	/*
	 * 警告提示消息
	 * _msg: 提示消息
	 * _callBack:回调
	 */
	commonLayer.prototype.confirm = function (_msg, _callBack) {
		layer.confirm(_msg, _callBack);
	};

	/*打开窗口
	 * _title: 标题
	 * _area: 区域
	 * _contentUrl: 内容URL
	 * _endCallBack：结束回调
	 */
	commonLayer.prototype.openMaxWin = function (_title, _area, _contentUrl, _endCallBack) {

		var _url = _contentUrl;
		if (_contentUrl.indexOf("?") != -1) {
			_url = _url + "&R=" + Math.floor(Math.random() * 100);
		} else {
			_url = _url + "?R=" + Math.floor(Math.random() * 100);
		}

		var index = layer.open({
			title: _title,
			offset: 'auto',
			type: 2,
			shade: false,
			maxmin: true,
			shade: 0.5,
			area: _area ? _area : ['100%', '100%'],
			content: _url,
			success: function (layero, index) {
				layer.full(index);
			},
			end: _endCallBack
		});

		return index;
	};

	/*打开窗口
	 * _title: 标题
	 * _area: 区域
	 * _contentUrl: 内容URL
	 * _endCallBack：结束回调
	 */
	commonLayer.prototype.openMaxWinToData = function (_title, _area, _contentUrl, _successCallBack) {
		var _url = _contentUrl;
		if (_contentUrl.indexOf("?") != -1) {
			_url = _url + "&R=" + Math.floor(Math.random() * 100);
		} else {
			_url = _url + "?R=" + Math.floor(Math.random() * 100);
		}

		var index = layer.open({
			title: _title,
			/*title: false,
			closeBtn: false,*/
			offset: 'auto',
			type: 2,
			shade: false,
			maxmin: true,
			shade: 0.5,
			area: _area ? _area : ['100%', '100%'],
			content: _url,
			success: function (layero, index) {
				layer.full(index);
				if (_successCallBack) {
					_successCallBack(layero, index);
				}
			}
		});

		return index;
	};

	/* 打开全屏无标题窗口
	 * _title: 标题
	 * _area: 区域
	 * _contentUrl: 内容URL
	 * _endCallBack：结束回调
	 */
	commonLayer.prototype.openMaxWinNoTitleToData = function (_contentUrl, _successCallBack, isVerson) {
		var _url = _contentUrl;
		if (isVerson === undefined || isVerson) {
			if (_contentUrl.indexOf("?") != -1) {
				_url = _url + "&R=" + Math.floor(Math.random() * 100);
			} else {
				_url = _url + "?R=" + Math.floor(Math.random() * 100);
			}
		}

		var index = layer.open({
			title: false,
			closeBtn: false,
			offset: 'auto',
			type: 2,
			shade: false,
			shade: 0.5,
			area: ['100%', '100%'],
			content: _url,
			success: function (layero, index) {
				//layer.full(index);
				if (_successCallBack) {
					_successCallBack(layero, index);
				}
			}
		});

		return index;
	};

	commonLayer.prototype.openCallBackWin = function (_title, _area, _contentUrl, _endCallBack) {
		var _url = _contentUrl;
		if (_contentUrl.indexOf("?") != -1) {
			_url = _url + "&R=" + Math.floor(Math.random() * 100);
		} else {
			_url = _url + "?R=" + Math.floor(Math.random() * 100);
		}

		var index = layer.open({
			title: _title,
			offset: 'auto',
			type: 2,
			shade: false,
			maxmin: true,
			shade: 0.5,
			area: _area ? _area : ['80%', '80%'],
			content: _url,
			end: _endCallBack
		});

		return index;
	};

	commonLayer.prototype.openWin = function (_title, _area, _maxmin, _contentUrl, _endCallBack, _cancelCallBack) {
		var _url = _contentUrl;
		if (_contentUrl.indexOf("?") != -1) {
			_url = _url + "&R=" + Math.floor(Math.random() * 100);
		} else {
			_url = _url + "?R=" + Math.floor(Math.random() * 100);
		}

		var index = layer.open({
			title: _title,
			offset: 'auto',
			type: 2,
			shade: false,
			maxmin: _maxmin,
			shade: 0.5,
			area: _area ? _area : ['80%', '80%'],
			content: _url,
			end: _endCallBack,
			cancel: _cancelCallBack
		});

		return index;
	};

	/*
	 * 确认框，支持
	 * _content: 提示消息
	 * _title: 标题
	 * _area: 大小
	 * _yesCallBack: 确定回调
	 * _cancelCallBack:取消回调
	 */
	commonLayer.prototype.confirmContent = function (_content, _title, _area, _icon, _yesCallBack, _cancelCallBack) {
		layer.confirm(_content, {
			type: 1,
			title: _title,
			icon: _icon ? _icon : -1,
			area: _area ? _area : ['60%', '60%']
		}, _yesCallBack, _cancelCallBack);

		/*layer.open({
			content: _content,
			btn: ["yes", "no"],
			yes: function(_index, _layero) {
				_yesCallBack(_index, _layero);
			},
			no: function(_index, _layero) {
				if(_cancelCallBack) {
					_cancelCallBack(_index, _layero);
				} else {
					_layero.close(_index);
				}
			}
		});*/

	};
	commonLayer.prototype.urlSearch = function () {
		var name, value;
		var str = location.href; //取得整个地址栏
		var data = {}
		var num = str.indexOf("?")
		str = str.substr(num + 1); //取得所有参数   stringvar.substr(start [, length ]
		var arr = str.split("&"); //各个参数放到数组里
		for (var i = 0; i < arr.length; i++) {
			num = arr[i].indexOf("=");
			if (num > 0) {
				name = decodeURI(arr[i].substring(0, num));
				value = arr[i].substr(num + 1);
				data[name] = value;
			}

		}
		return data

	}
	var _layer = new commonLayer();
	exports("commonLayer", function (option) {
		return _layer.set(option);
	});
});
